<template>
	<view>
		<view style="padding:30rpx">
			<u-row>
				<u-col span="8">
					<u-input placeholder="请输入规格名" border v-model="specName"></u-input>
				</u-col>
				<u-col span="4">
					<u-button type="primary" size="medium" style="width: 100%;" @click="editSpec">确认修改</u-button>
				</u-col>
			</u-row>
		</view>
		<u-gap height="10" bg-color="#f2f2f2"></u-gap>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				specName: '',
				id:'',
				productId:''
			}
		},
		onLoad(option) {
			console.log(option)
			this.specName = option.specName;
			this.productId = option.productId;
			this.id = option.id;
		},
		methods: {
			editSpec() {
				this.$u.api.editSpec({
					id: this.id,
					productId: this.productId,
					sortLevel: 0,
					specName: this.specName
				}).then(res => {
					if(res.code==0){
						this.$u.toast('修改成功');
						let pages = getCurrentPages();
						let currPage = pages[pages.length - 2];
						currPage.$vm.getData();
						setTimeout(function(){
							uni.navigateBack();
						},1500)
					}else{
						this.$u.toast(res.msg);
					}
				})

			}
		}
	}
</script>

<style>
</style>
